#pragma once

#include <iostream>
#include "Protocol.hpp"

class Calculator
{
public:
    Calculator()
    {
    }
    Response Excute(const Request &req)
    {
        Response resp;
        switch (req.Oper())
        {
        case '+':
            resp.SetResult(req.X() + req.Y());
            break;
        case '-':
            resp.SetResult(req.X() - req.Y());
            break;
        case '*':
            resp.SetResult(req.X() * req.Y());
            break;
        case '/':
            if(req.Y() == 0)
                resp.SetCode(1); // 1就是除零
            else
                resp.SetResult(req.X() / req.Y());
            break;
        case '%':
            if(req.Y() == 0)
                resp.SetCode(2);//2就是 mod 0
            else
                resp.SetResult(req.X() % req.Y());
            break;
        default:
            break;
        }
        return resp;
    }
    ~Calculator()
    {
    }

private:
};